package codeTop;

/**
 * q440
 *
 * @author 雨凡
 * @version q440.java, v0.1
 * @date 2025/07/01/13:11
 */
public class q440 {
    public int findKthNumber(int n, int k) {
        int curr = 1;
        while (k > 0) {
            int count = getChildNodeCount(curr, n);
            if (k >= count) {
                k-=count;
                curr++;
            }else {
                k--;
                curr *= 10;
            }
        }
        return curr;
    }
    int getChildNodeCount(int curr,int  n){
        int count = 0;
        long left = curr;
        long right = curr;
        while (left <= n) {
            count += Math.min(right, n) - left + 1;
            left *= 10;
            right = right * 10 + 9;
        }
        return count;
    }

    public static void main(String[] args) {
        q440 q = new q440();
        System.out.println(q.findKthNumber(13, 2));
    }
}
